{include file="public/toper" /}
<div class="x-body">
    <div class="layui-row">
        <div class="layui-form layui-col-md12 x-so">
            <input type="text" name="sreach" value=""  style="width:250px;" id="key"   placeholder="请输入名称/" autocomplete="off" class="layui-input">
            <div class="layui-input-inline">
                <select name="type" id="type">
                    <option value=".">全部</option>
                    {volist name="list" id="vo"}
                    <option value="{$vo.store_id}">{$vo.name}</option>
                    {/volist}
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="state" id="state">
                    <option value=".">全部</option>
                    <option value="1">否</option>
                    <option value="2">是</option>
                </select>
            </div>
            <button class="layui-btn" id="search"><i class="layui-icon">&#xe615;</i></button>
        </div>
    </div>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">选择</button>
    </div>
</script>
<script type="text/html" id="image">
    <img src="{{d.img}}" class="thumb" thumb="{{ d.img }}"/>
</script>
<script>
    layui.use(['table','util'], function(){
        var table = layui.table, $ = layui.jquery;
        var layer = layui.layer;
        var loading = layer.load(1, {shade: [0.1,'#fff'] });
        var tableIn = table.render({
            method: 'post',
            elem: '#test'
            ,url: "{:url('Goods/themegoods')}"
            ,id:'test'
            ,cols: [[
                {type:'checkbox'}
                ,{field:'name',width: 250,title: '商品名称', align: 'center'}
                ,{width:100, title: '缩略图',align: 'center',toolbar:'#image'}
                ,{field:'label',width: 100,title: '标签', align: 'center'}
                ,{field:'sname',width: 150,title: '所属门店', align: 'center'}
                ,{field:'large',width: 100,title: '销售价', align: 'center'}
                ,{fiedl:'sale_type',width:80,title: '可共享',align: 'center',templet: function(d){if(d.sale_type==1){ return '否';}else if (d.sale_type==2){ return '是';}}}
            ]]
            ,page: true
            ,limit: 30
            ,limits:[30,60,90,120,150,180,210,240,270,300]
            ,toolbar: '#toolbarDemo'
            ,defaultToolbar:[]
        });
        layer.close(loading);

        //搜索
        $('#search').on('click', function () {
            tableIn.reload({
                where: {key: $('#key').val(),type:$('#type').val(),state:$('#state').val()}
                ,page: {curr: 1 }
            });
        });
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;

                    var goods = new Array();
                    if(data.length<1){
                        layer.msg("请选择商品");
                        return false;
                    }

                    for(var i=0;i<data.length;i++){
                        goods[i] = data[i].goods_id;
                    }

                    var theme_id ={$theme_id};
                    $.ajax({
                        type: "POST",
                        data:{id:goods,theme_id:theme_id},
                        url:  "{:url('Theme/add2')}",
                        success: function(res) {
                            if(res.code==0){
                                layer.msg("添加失败");
                                return false;
                            }else {
                                layer.alert(res.msg, {icon: 6},function () {
                                    // 获得frame索引
                                    var index = parent.layer.getFrameIndex(window.name);
                                    //关闭当前frame
                                    parent.layer.close(index);
                                    parent.location.reload();
                                })
                            }
                        }
                    });
                    break;

            };
        });
    });
</script>
{include file="public/footer"/}